//
//  WeatherModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/26.
//

#import "WeatherModel.h"
@interface WeatherModel ()

@end
@implementation WeatherModel

+ (instancetype)shared{
    static dispatch_once_t onceToken;
    static WeatherModel *sharedManager;
    dispatch_once(&onceToken, ^{
        sharedManager = [[WeatherModel alloc]init];
    });
    
    return sharedManager;
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"hourly":[WeatherHearModel class],
        @"daily":[WeatherDayModel class],
    };
}

- (WeatherHearModel *)hourlyModel{
    for (WeatherHearModel * model in self.hourly) {
        NSString * time = [[model.fxTime componentsSeparatedByString:@"T"].lastObject componentsSeparatedByString:@"+"].firstObject;
        if([time isEqualToString:[NSString stringWithFormat:@"%@:00", [NSDate br_stringFromDate:[NSDate new] dateFormat:@"HH"]]] ){
            return model;
        }
    }
    return nil;
}
- (WeatherDayModel *)dailyModel{
    for (WeatherDayModel * model in self.daily) {
        if([model.fxDate isEqualToString:[NSDate br_stringFromDate:[NSDate new] dateFormat:@"yyyy-MM-dd"]] ){
            return model;
        }
    }
    return nil;
}
@end

@implementation WeatherHearModel
@end

@implementation WeatherDayModel
@end

